const { query } = require('./config/database')

async function checkBookshelfStructure () {
  try {
    console.log('🔍 检查书架和阅读历史表结构...\n')

    // 检查 user_bookshelf 表结构
    console.log('📚 user_bookshelf 表结构:')
    const bookshelfStructure = await query('DESCRIBE user_bookshelf')
    console.table(bookshelfStructure)

    console.log('\n📖 reading_history 表结构:')
    const historyStructure = await query('DESCRIBE reading_history')
    console.table(historyStructure)

    console.log('\n📊 现有数据统计:')
    const bookshelfCount = await query(
      'SELECT COUNT(*) as count FROM user_bookshelf'
    )
    const historyCount = await query(
      'SELECT COUNT(*) as count FROM reading_history'
    )

    console.log(`📚 书架记录数: ${bookshelfCount[0].count}`)
    console.log(`📖 阅读历史记录数: ${historyCount[0].count}`)
  } catch (error) {
    console.error('❌ 检查过程中出现错误：', error)
  } finally {
    process.exit(0)
  }
}

checkBookshelfStructure()
